<?php
if( !defined('IN_INDEX') )
{
	posterror("ACCESS DENIED", "This page is hidden.");
	exit;
}
if(!checkSession())
{
			function redirect($url)
			{
			?>
				<script type="text/javascript">
					{
					window.location = "<?=$url?>";
					}
				</script>
			<?php 
			}
			redirect("index.php?action=login");
	exit;
}
if(isset($_POST['settings_submit']))
{
	$settings_checked = 0;
	if(isset($_POST['blog_privacy']))
	{
		$USER->setBlogPrivacy($_POST['blog_privacy']);
		$settings_checked++;
	}

	if(isset($_POST['blog_get_comments']) )
	{
		$USER->setMsgFromComments($_POST['blog_get_comments']);
		$settings_checked++;
	}
	
	if(isset($_POST['blog_show_bw']) )
	{
		$USER->setShowBw($_POST['blog_show_bw']);
		$settings_checked++;
	}
	
	if(isset($_POST['blogs_per_page']))
	{
		$USER->setBlogsPerPage($_POST['blogs_per_page']);
		$settings_checked++;
	}
	
	if(isset($_POST['show_blog_comments']))
	{
		$USER->setShowBlogComments($_POST['show_blog_comments']);
		$settings_checked++;
	}
	
	if(isset($_POST['sort_comments']))
	{
		$USER->setSortComments($_POST['sort_comments']);
		$settings_checked++;
	}
	
	if(isset($_POST['sort_kg_reps']))
	{
		$USER->setSortKgReps($_POST['sort_kg_reps']);
		$settings_checked++;
	}
	
	if(isset($_POST['show_training_in_blog']))
	{
		$USER->setShowTrainingInBlog($_POST['show_training_in_blog']);
		$settings_checked++;
	}
	
	if(isset($_POST['show_weightchange']))
	{
		$USER->setShowWeightchange($_POST['show_weightchange']);
		$settings_checked++;
	}
	
	if(isset($_POST['show_pb']))
	{
		$USER->setShowPb($_POST['show_pb']);
		$settings_checked++;
	}
	
	if(isset($_POST['activate_rpe']))
	{
		$USER->setActivateRpe($_POST['activate_rpe']);
		$settings_checked++;
	}
	
	if(isset($_POST['comments_per_page']))
	{
		$USER->setCommentsPerPage($_POST['comments_per_page']);
		$settings_checked++;
	}
	
	if($settings_checked > 0)
	{
		$USER->update();
		echo"<center><meta http-equiv=\"refresh\"content=\"2;url=index.php?action=profile&sub=edit_blog\">";
		echo "<br /><br /><br /><br /><br /><br /><br /><br /><br />
		<h2>" . ucfirst(translate('settings_saved')) . "</h2>\n";
		echo "<br/>" . translate('redirectedin'). " <a href=\"index.php?action=profile&sub=edit_blog\">" . translate('clickhere') . "</a>.</center>
		<div class='fixed'>
					</div>
				</div>
				</div>
			<div class='fixed'>
			</div>
			<div id='footer'>
			<a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" . translate('top') . "</a>
				<div align='center' id='copyright'>&copy; " . translate('copyrightyear') . " " . translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" . translate('contact') ."</a> - <a href='index.php?action=about'>" . translate('about') . "</a> - " . translate('onlineusers'). ": " . getActiveUsers() . "<br />
                </div>";
		exit;
	}
}
$array_privacy = array(0 => "public", 2 => "friends", 1 => "restricted");
$array_yesno = array(1 => "yes", 0 => "no");
$array_order_metric_reps = array(1 => "metric_x_reps", 0 => "reps_x_metric");
$array_posts = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30, 50, 100, 200, 500, 1000);
$array_commentsort = array("comment_date" => "comment_newest_last", "-comment_date" => "comment_newest_first");
?>
<div id='postpath'>
	<a title="<?php echo translate('gotofrontpage'); ?>" href="index.php"><?php echo translate('home'); ?></a>
    &gt; <a href="index.php?action=blogs" title='<?php echo translate('showallblogs'); ?>'><?php echo translate('blog'); ?></a> 
    &gt; <a href="index.php?action=profile&id=<?php echo $USER->getId(); ?>"><?php echo ucf($USER->getFirstname()) . " " . ucf($USER->getLastname()); ?></a>
	&gt; <a href="index.php?action=profile&sub=edit" title='<?php echo translate('edit'); ?>'><?php echo translate('edit'); ?></a> 
	&gt; <a href="index.php?action=profile&sub=edit_blog" title='<?php echo translate('blogsettings'); ?>'><?php echo translate('blogsettings'); ?></a> 
</div>
<br />

<h2><?php echo translate('blogsettings2'); ?></h2>
<br />

<form action="index.php?action=profile&sub=edit_blog" method="post" id="general_settings" name="general_settings">   
	<table border="1" width="100%" cellspacing="0" cellpadding="4">
		<tr>
			<td width="37%" valign="top">
				<img src="img/pp_edit.png" /> <b><?php echo translate('showmyblog'); ?></b>
				<div class="set_subtext"><?php echo translate('Choosetoshowyourblogorhideit'); ?></div>
			</td>
			<td>
				<div>
					<?php
					foreach($array_privacy as $key => $val)
					{
						if($val == "restricted") 
						{ 
						$yesno = "no"; 
						}
						if($val == "friends") 
						{ 
						$yesno = "friends"; 
						} 
						if($val == "public")
						{ 
						$yesno = "yes"; 
						}
						echo "<input type=\"radio\" name=\"blog_privacy\" value=\"" . $key . "\"";
						if($key == $USER->getBlogPrivacy())
						{
							echo " checked=\"checked=\"";
						}
						echo " > <span class=\"" .$yesno . "\">" . translate($val) . "</span>\n";
					}
					?>
				</div>
			</td>
		</tr>
		<tr>
			<td width="37%" valign="top">
				<img src="img/ppp_edit.png" /> <b><?php echo translate('postprpage'); ?></b>
				<div class="set_subtext"><?php echo translate('choosethenumberofpostyouwanttodisplayprpage'); ?></div>
			</td>
            
			<td width="63%">
				<select name="blogs_per_page">
				<?php
					foreach($array_posts as $key => $val)
					{
						if($val == $USER->getBlogsPerPage())
						{
							echo "<option value=\"" . $val . "\" selected=\"selected\">" . $val . "</option>\n";
						}
						else
						{
							echo "<option value=\"" . $val . "\">" . $val . "</option>\n";
						}
					}
				?>
				</select>
			</td>
		</tr>
        <tr>
			<td width="37%" valign="top">
				<img src="img/wm_edit.png" /> <b><?php echo translate('showmybw'); ?></b>
				<div class="set_subtext"><?php echo translate('Choosetoshowbworhideit'); ?></div>
			</td>
			<td>
				<div>
					<?php
					foreach($array_yesno as $key => $val)
					{
						if($val == "no") { $yesno = "no"; } else { $yesno = "yes"; }
						echo "<input type=\"radio\" name=\"blog_show_bw\" value=\"" . $key . "\"";
						if($key == $USER->getShowBw())
						{
							echo " checked=\"checked=\"";
						}
						echo " > <span class=\"" .$yesno . "\">" . translate($val) . "</span>\n";
					}
					?>
				</div>
			</td>
		</tr>
        </table>
        <br />
    <h2><?php echo ucf(translate('trainingsettings')); ?> </h2>
    <br />
        <table border="1" width="100%" cellspacing="0" cellpadding="4">
         <tr>
			<td width="37%" valign="top">
				<img src="img/report.png" /> <b><?php echo translate('showmytraining'); ?></b>
				<div class="set_subtext"><?php echo translate('Choosetoshowtrainingorhideit'); ?></div>
			</td>
			<td>
				<div>
					<?php
					foreach($array_yesno as $key => $val)
					{
						if($val == "no") { $yesno = "no"; } else { $yesno = "yes"; }
						echo "<input type=\"radio\" name=\"show_training_in_blog\" value=\"" . $key . "\"";
						if($key == $USER->getShowTrainingInBlog())
						{
							echo " checked=\"checked=\"";
						}
						echo " > <span class=\"" .$yesno . "\">" . translate($val) . "</span>\n";
					}
					?>
				</div>
			</td>
		</tr>
        
        <tr>
			<td width="37%" valign="top">
				<img src="img/reverse.png" /> <b><?php echo translate('sort_kg_reps'); ?></b>
				<div class="set_subtext"><?php echo translate('Choosehowyouwannasortkgreps'); ?></div>
			</td>
			<td>
				<div>
					<?php
					foreach($array_order_metric_reps as $key => $val)
					{
						if($val == "no") { $yesno = "no"; } else { $yesno = "yes"; }
						echo "<input type=\"radio\" name=\"sort_kg_reps\" value=\"" . $key . "\"";
						if($key == $USER->getSortKgReps())
						{
							echo " checked=\"checked=\"";
						}
						echo " > " . translate($val) . "\n";
					}
					?>
				</div>
			</td>
		</tr>
        
        <tr>
			<td width="37%" valign="top">
				<img src="img/arrow_switch.png" /> <b><?php echo translate('show_weightchange'); ?></b>
				<div class="set_subtext"><?php echo translate('Choosetoshowweightchange'); ?></div>
			</td>
			<td>
				<div>
					<?php
					foreach($array_yesno as $key => $val)
					{
						if($val == "no") { $yesno = "no"; } else { $yesno = "yes"; }
						echo "<input type=\"radio\" name=\"show_weightchange\" value=\"" . $key . "\"";
						if($key == $USER->getShowWeightchange())
						{
							echo " checked=\"checked=\"";
						}
						echo " > <span class=\"" .$yesno . "\">" . translate($val) . "</span>\n";
					}
					?>
				</div>
			</td>
		</tr>
        
        <tr>
			<td width="37%" valign="top">
				<img src="img/star.png" /> <b><?php echo translate('show_pb'); ?></b>
				<div class="set_subtext"><?php echo translate('Choosetoshowpb'); ?></div>
			</td>
			<td>
				<div>
					<?php
					foreach($array_yesno as $key => $val)
					{
						if($val == "no") { $yesno = "no"; } else { $yesno = "yes"; }
						echo "<input type=\"radio\" name=\"show_pb\" value=\"" . $key . "\"";
						if($key == $USER->getShowPb())
						{
							echo " checked=\"checked=\"";
						}
						echo " > <span class=\"" .$yesno . "\">" . translate($val) . "</span>\n";
					}
					?>
				</div>
			</td>
		</tr>
        
         <tr>
			<td width="37%" valign="top">
				<img src="img/rpe.png" /> <b><?php echo translate('activate_rpe'); ?></b>
				<div class="set_subtext"><?php echo translate('Choosetoactivate_rpe'); ?></div>
			</td>
			<td>
				<div>
					<?php
					foreach($array_yesno as $key => $val)
					{
						if($val == "no") { $yesno = "no"; } else { $yesno = "yes"; }
						echo "<input type=\"radio\" name=\"activate_rpe\" value=\"" . $key . "\"";
						if($key == $USER->getActivateRpe())
						{
							echo " checked=\"checked=\"";
						}
						echo " > <span class=\"" .$yesno . "\">" . translate($val) . "</span>\n";
					}
					?>
				</div>
			</td>
		</tr>
           
	</table>
    <br />
    <h2><?php echo ucf(translate('commentssettings')); ?> </h2>
    <br />
    <table border="1" width="100%" cellspacing="0" cellpadding="4">    
    	<tr>
			<td width="37%" valign="top">
				<img src="img/com_edit.png" /> <b><?php echo translate('comment_sort_view'); ?></b>
				<div class="set_subtext"><?php echo translate('comment_sort_view_subtext'); ?></div>
			</td>
			<td>
                <select name="sort_comments">
					<?php
					foreach($array_commentsort as $key => $val)
					{
						if($key == $USER->getSortComments())
						{
							echo "<option value=\"" . $key . "\" selected=\"selected\">" . translate($val) . "</option>\n";
						}
						else
						{
							echo "<option value=\"" . $key . "\">" . translate($val) . "</option>\n";
						}
					}
				?>
                </select>
			</td>
		</tr>
        <tr>
			<td width="37%" valign="top">
				<img src="img/comments.png" /> <b><?php echo translate('commentsprpage'); ?></b>
				<div class="set_subtext"><?php echo translate('choosethenumberofcommentsyouwanttodisplayprpage'); ?></div>
			</td>
            
			<td width="63%">
				<select name="comments_per_page">
				<?php
					foreach($array_posts as $key => $val)
					{
						if($val == $USER->getCommentsPerPage())
						{
							echo "<option value=\"" . $val . "\" selected=\"selected\">" . $val . "</option>\n";
						}
						else
						{
							echo "<option value=\"" . $val . "\">" . $val . "</option>\n";
						}
					}
				?>
				</select>
			</td>
		</tr>
        <tr>
			<td width="37%" valign="top">
				<img src="img/comment_add.png" /> <b><?php echo translate('getpmoncomments'); ?></b>
				<div class="set_subtext"><?php echo translate('enableordisableifyouwanttorecieveaPMwhensomeonecommentsonyourblog'); ?></div>
			</td>
			<td>
				<div>
					<?php
					foreach($array_yesno as $key => $val)
					{
						if($val == "no") { $yesno = "no"; } else { $yesno = "yes"; }
						echo "<input type=\"radio\" name=\"blog_get_comments\" value=\"" . $key . "\"";
						if($key == $USER->getMsgFromComments())
						{
							echo " checked=\"checked=\"";
						}
						echo " > <span class=\"" .$yesno . "\">" . translate($val) . "</span>\n";
					}
					?>
				</div>
			</td>
		</tr>
        <tr>
			<td width="37%" valign="top">
				<img src="img/comments.png" /> <b><?php echo translate('showlastcomments'); ?></b>
				<div class="set_subtext"><?php echo translate('choosetoshoworhidecomments'); ?></div>
			</td>
			<td width="63%">
				<div>
					<?php
					foreach($array_yesno as $key => $val)
					{
						if($val == "no") { $yesno = "no"; } else { $yesno = "yes"; }
						echo "<input type=\"radio\" name=\"show_blog_comments\" value=\"" . $key . "\"";
						if($key == $USER->getShowBlogComments())
						{
							echo " checked=\"checked=\"";
						}
						echo " > <span class=\"" .$yesno . "\">" . translate($val) . "</span>\n";
					}
					?>
				</div>
			</td>
		</tr>
    </table>
	<br />   
	<input style="font-weight:bold;" type="submit" value=" <?php echo translate('save'); ?> " name="settings_submit" />   
</form>